package pro.unal.edu.datasource;

import java.awt.Color;
import pro.unal.edu.filter.MyPoint;

/**
 * @author Carlos Eduardo Bernal Cárdenas
 * @version 1.0
 * @created 17-ago-2011 03:55:41 p.m.
 */
public abstract class MyImage {

    private int width;
    private int height;
    private String type;
    private int fileSize;
    private String pathImage;
    private boolean littleEndian = true;
    private String signature;
    private int offset;
    private Color[][] dataImageColor;

    public final int readBytes(int data, byte[] arrBytes, int from) {
        int temp = 0;
        if (littleEndian) {
            for (int i = from; i < from + data; i++) {
                temp += (arrBytes[i] + 256) % 256 * ((int) Math.pow(256, i - from));
//                System.out.println("i:" + (i));
            }
        } else {
            for (int i = from; i < from + data; i++) {
                temp += (arrBytes[i] + 256) % 256 * ((int) Math.pow(256, data - i - 1));
//                System.out.println("i:" + (data - i - 1));
            }
        }
        return temp;
    }

    public static void main(String[] args) {
        BMPImage bMPImage = new BMPImage();
//        byte[] bytes = new byte[3];
        byte[] bytes = {0, 0, 5};
        System.out.println(bMPImage.readBytes(bytes.length, bytes, 0));
    }

    public final Color[][] getDataImageColor() {
        return dataImageColor;
    }
    
    public final void setDataImageColor(Color[][] dataImageColor) {
        this.dataImageColor = dataImageColor.clone();
//        this.dataImageColor = new Color[dataImageColor[0].length][dataImageColor.length];
//        this.dataImageColor = dataImageColor;
    }


    public final void setDataImageColor(MyPoint[][] dataImageColor) {
        this.dataImageColor = new Color[dataImageColor.length][dataImageColor[0].length];
        for (int i = 0; i < dataImageColor.length - 1; i++) {
            for (int j = 0; j < dataImageColor[0].length - 1; j++) {
                if (dataImageColor[i][j] != null) {
                    this.dataImageColor[i][j] = dataImageColor[i][j].getColor();
                }
            }
        }
    }

    public final int getFileSize() {
        return fileSize;
    }

    protected abstract void loadImageProperties();
    
    public final void setFileSize(int fileSize) {
        this.fileSize = fileSize;
    }

    public final int getHeight() {
        return height;
    }

    public final void setHeight(int height) {
        this.height = height;
    }

    public final String getPathImage() {
        return pathImage;
    }

    public final void setPathImage(String pathImage) {
        this.pathImage = pathImage;
    }

    public final String getType() {
        return type;
    }

    public final void setType(String type) {
        this.type = type;
    }

    public final int getWidth() {
        return width;
    }

    public final void setWidth(int width) {
        this.width = width;
    }

    public final boolean isLittleEndian() {
        return littleEndian;
    }

    public final void setLittleEndian(boolean littleEndian) {
        this.littleEndian = littleEndian;
    }

    public final String getSignature() {
        return signature;
    }

    public final void setSignature(String signature) {
        this.signature = signature;
    }

    public final int getOffset() {
        return offset;
    }

    public final void setOffset(int offset) {
        this.offset = offset;
    }
}